const net = require('net');
const fs = require('fs');
const server = net.createServer((c) => {
    // 'connection' // 相当于调用  server.on('connection') 事件
    // 当一个新的connection建立的时候触发. socket 是一个 net.Socket的实例对象.
    console.log('c', c)
    console.log('client connected');

    console.log('监听的地址', c.remoteAddress)
    console.log('监听的端口', c.remotePort)

    c.on('data', (data) => {
        console.log('data server ', data.toString());
    });

    c.on('end', () => {
        console.log('client disconnected');
    });
    c.write('hello\r\n');
    c.pipe(c);
});


server.on('error', (err) => {
    throw err;
});


server.on('data', (data) => {
    console.log('data server ', data.toString());
});

server.listen(8124, () => {
    console.log('server bound');
});


